function createMenu(systemName){
	document.write("<table id=\"menuTable\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
	document.write("	<tbody>");
	document.write("		<tr id=\"menuTr00\">");
	document.write("			<td>");
	document.write("				<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
	document.write("					<tr>");
	document.write("						<td width=\"20px\" valign=\"top\" >");
	document.write("							<img border=\"0\" src=\"./image/menu/ftv2folderopen.gif\" style=\"vertical-align:top;\" />");
	document.write("						</td>");
	document.write("						<td valign=\"top\" style=\"word-break:keep-all;white-space:nowrap;\">");
	document.write("							"+systemName);
	document.write("						</td>");
	document.write("					</tr>");
	document.write("				</table>");
	document.write("			</td>");
	document.write("		</tr>");
	document.write("	</tbody>");
	document.write("</table>");
}

function addMenuItem(itemType, itemId, itemName, target, website){
	var tableObj = document.getElementById("menuTable");
	var row = tableObj.insertRow(tableObj.rows.length);
	row.id = "menuTr" + itemId;
	var cell = row.insertCell(0);
	var str = "";
	str += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
	str += "<tr>";
	var tdWidth = 0;
	var level = 0;
	if(itemId.indexOf("_") > -1){
		level = itemId.split("_").length;
		tdWidth = 58 + 16*(level-2);
	}else{
		tdWidth = 44;
	}
	str += "<td id=\"menuTd"+itemId+"\" width=\""+tdWidth+"px\" valign=\"top\" >";
	str += "</td>";
	if(itemType == "folder"){
		str += "<td id=\"folderTd_"+itemId+"\" valign=\"top\" style=\"word-break:keep-all;white-space:nowrap;\">";
	}else{
		str += "<td valign=\"top\" style=\"word-break:keep-all;white-space:nowrap;\">";
	}
	
	if (website != "") {
		str += "<a href=\""+website+"\" target=\""+target+"\">";
		str += itemName;
		str += "</a>";
	} else {
		str += itemName;
	}
	str += "</td>";
	str += "</tr>";
	str += "</table>";
	cell.innerHTML = str;
	if(itemId.indexOf("_") > -1){
		row.style.display = "none";
	}
}

function createMenuEnd(){
	var tableObj = document.getElementById("menuTable");
	for(var x=1; x<tableObj.rows.length; x++){
		var str = "";
		var checkNum = 0;
		var menuId = tableObj.rows[x].id.substr(6);
		var rowId = tableObj.rows[x].id;
		var cellId = "menuTd" + menuId;

		var level = rowId.split("_");
		var arrayLevel = "";

		//計算每一階層所採用的圖片
		for(var y=0; y<level.length; y++){
			arrayLevel += "_"+level[y];

			//除最後一階層不需判斷要放直線或空格
			if(y!=level.length-1){
				if(arrayLevel.substr(7).lastIndexOf("_") > -1){
					var folderId = arrayLevel.substr(7).substr(arrayLevel.substr(7).lastIndexOf("_")+1);
					folerId = arrayLevel.substr(7).substr(0, arrayLevel.substr(7).lastIndexOf("_")+1) + StringUtil.lPad(String(Number(folderId)+1), 2, "0");
				}else{
					var folerId = StringUtil.lPad(String(Number(arrayLevel.substr(7))+1), 2, "0");
				}
				
				var tempLastFolderId = "menuTr" + folerId;

				if(document.getElementById(tempLastFolderId)==null){
					str += "<img border=\"0\" src=\"./image/menu/ftv2blank.gif\" style=\"vertical-align:top;\"/>";
				}else{
					str += "<img border=\"0\" src=\"./image/menu/ftv2vertline.gif\" style=\"vertical-align:top;\"/>";
				}
				checkNum++;
			}else{
				var folderTd="folderTd_"+menuId;
				if(x+1<tableObj.rows.length){
					var nextRowId = tableObj.rows[x+1].id;
					if(menuId.lastIndexOf("_") > -1){
						var folderId = menuId.substr(menuId.lastIndexOf("_")+1);
						folerId = menuId.substr(0, menuId.lastIndexOf("_")+1) + StringUtil.lPad(String(Number(folderId)+1), 2, "0");
					}else{
						var folerId = StringUtil.lPad(String(Number(menuId)+1), 2, "0");
						
					}
					
					var tempLastFolderId = "menuTr" + folerId;

					if(document.getElementById(tempLastFolderId)==null){									
						if(document.getElementById(folderTd)!=null){
							str += "<a href=\"javascript:\" onclick=\"controlMenuFolder('open', '"+menuId+"');return false;\">";
							str += "<img border=\"0\" src=\"./image/menu/ftv2plastnode.gif\" style=\"vertical-align:top;\"/>";
							str += "</a>";
						}else{
							str += "<img border=\"0\" src=\"./image/menu/ftv2lastnode.gif\" style=\"vertical-align:top;\"/>";
						}
					}else{
						if(document.getElementById(folderTd)!=null){
							str += "<a href=\"javascript:\" onclick=\"controlMenuFolder('open', '"+menuId+"');return false;\">";
							str += "<img border=\"0\" src=\"./image/menu/ftv2pnode.gif\" style=\"vertical-align:top;\"/>";
							str += "</a>";
						}else{
							str += "<img border=\"0\" src=\"./image/menu/ftv2node.gif\" style=\"vertical-align:top;\"/>";
						}
					}
				}else{
					if(document.getElementById(folderTd)!=null){
						str += "<a href=\"javascript:\" onclick=\"controlMenuFolder('open', '"+menuId+"');return false;\">";
						str += "<img border=\"0\" src=\"./image/menu/ftv2plastnode.gif\" style=\"vertical-align:top;\"/>";
						str += "</a>";
					}else{
						str += "<img border=\"0\" src=\"./image/menu/ftv2lastnode.gif\" style=\"vertical-align:top;\"/>";
					}
				}
				checkNum++;
			}

			if(checkNum == level.length){
				if(document.getElementById(folderTd)!=null){
					str += "<img border=\"0\" src=\"./image/menu/ftv2folderclosed.gif\"  style=\"vertical-align:top;\"/>";
				}else{
					str += "<img border=\"0\" src=\"./image/menu/ftv2doc.gif\"  style=\"vertical-align:top;\"/>";
				}
				document.getElementById(cellId).innerHTML = str;
				//continue;
			}
		}
		//document.getElementById(cellId).innerHTML = str;
	}
}

function controlMenuFolder(action, menuFolderId){
	var lastFolderFlag = true;
	var level = 0;
	if(menuFolderId.lastIndexOf("_") > -1){
		level = menuFolderId.split("_").length;
		var folderId = menuFolderId.substr(menuFolderId.lastIndexOf("_")+1);
		folerId = menuFolderId.substr(0, menuFolderId.lastIndexOf("_")+1) + StringUtil.lPad(String(Number(folderId)+1), 2, "0");
	}else{
		var folerId = StringUtil.lPad(String(Number(menuFolderId)+1), 2, "0");
	}
	var tempLastFolderId = "menuTr" + folerId;
	var menuTrId = "menuTr" + menuFolderId;
	var menuTdId = "menuTd" + menuFolderId;

	var tableObj = document.getElementById("menuTable");
	var length = menuTrId.length;
	for(var i=0; i<tableObj.rows.length; i++){
		var rowId = tableObj.rows[i].id;
		if(rowId.substr(0, length) == menuTrId){
			if(rowId != menuTrId){
				if(action=="open"){
					//表示同一層
					if(rowId.length == menuTrId.length + 3){
						if(document.getElementById("folderTd_"+rowId.substr(6))!=null){
							controlMenuFolder("close", rowId.substr(6));								}
							document.getElementById(rowId).style.display = "";
						}
				}else if(action=="close"){
					document.getElementById(rowId).style.display = "none";
				}
			}
		}
		if(rowId.substr(0, length) == tempLastFolderId){
			lastFolderFlag = false;
		}
	}

	var str = "";
	if(level > 0){
		var alevel = menuFolderId.split("_");
		var arrayLevel = "";
		for(var y=0; y<alevel.length-1; y++){
			arrayLevel += "_"+alevel[y];
			if(y!=level.length-1){
				if(arrayLevel.substr(1).lastIndexOf("_") > -1){
					var folderId = arrayLevel.substr(1).substr(arrayLevel.substr(1).lastIndexOf("_")+1);
					folerId = arrayLevel.substr(1).substr(0, arrayLevel.substr(1).lastIndexOf("_")+1) + StringUtil.lPad(String(Number(folderId)+1), 2, "0");
				}else{
					var folerId = StringUtil.lPad(String(Number(arrayLevel.substr(1))+1), 2, "0");
				}
				
				//var tempLastFolderId = ;
				/*
				var nextNo = 0;
				var length = rowId.length;
				for(var z=0; z<tableObj.rows.length; z++){
					var arowId = tableObj.rows[z].id;
					if(arowId == tempLastFolderId){
						nextNo++;
					}
				}
				*/
				if(document.getElementById("menuTr" + folerId)==null){
					str += "<img border=\"0\" src=\"./image/menu/ftv2blank.gif\" style=\"vertical-align:top;\"/>";
				}else{
					str += "<img border=\"0\" src=\"./image/menu/ftv2vertline.gif\" style=\"vertical-align:top;\"/>";
				}
			}
		}
	}
	if(action=="open"){
		str += "<a href=\"javascript:\" onclick=\"controlMenuFolder('close', '"+menuFolderId+"');return false;\">";
	}else if(action=="close"){
		str += "<a href=\"javascript:\" onclick=\"controlMenuFolder('open', '"+menuFolderId+"');return false;\">";
	}
	if(document.getElementById(tempLastFolderId)==null){
//	if(lastFolderFlag == true){
		if(action=="open"){
			str += "<img border=\"0\" src=\"./image/menu/ftv2mlastnode.gif\" style=\"vertical-align:top;\"/>";
		}else if(action=="close"){
			str += "<img border=\"0\" src=\"./image/menu/ftv2plastnode.gif\" style=\"vertical-align:top;\"/>";
		}
	}else{
		if(action=="open"){
			str += "<img border=\"0\" src=\"./image/menu/ftv2mnode.gif\" style=\"vertical-align:top;\"/>";
		}else if(action=="close"){
			str += "<img border=\"0\" src=\"./image/menu/ftv2pnode.gif\" style=\"vertical-align:top;\"/>";
		}
	}
	str += "</a>";
	if(action=="open"){
	    str += "<img border=\"0\" src=\"./image/menu/ftv2folderopen.gif\" style=\"vertical-align:top;\"/>";
	}else if(action=="close"){
    	str += "<img border=\"0\" src=\"./image/menu/ftv2folderclosed.gif\" style=\"vertical-align:top;\"/>";
	}
	document.getElementById(menuTdId).innerHTML = str;
}
		